package com.wltt.product.ahuthr.service;

import com.wltt.product.ahuthr.mapper.SystemPostMapper;
import com.wltt.product.ahuthr.model.ResultData;
import com.wltt.product.ahuthr.model.po.SystemPostPO;
import com.wltt.product.ahuthr.model.vo.QuerySystemPostByTypeReq;
import com.wltt.product.ahuthr.model.vo.QuerySystemPostByTypeRsp;
import com.wltt.product.ahuthr.model.vo.QuerySystemPostTypeRsp;
import com.wltt.product.ahuthr.service.base.BaseServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;


/**
 * @ClassName: SystemPostServiceImpl
 * @Description: 逻辑服务类<br />
 * 不做业务校验，参数校验统一放到前置的Service中
 * @Date: 2024-05-30 14:34:21
 * @Author yanggl
 */
@Service(value = "systemPostService")
public class SystemPostServiceImpl extends BaseServiceImpl<SystemPostPO, Long> implements SystemPostService {

    private SystemPostMapper systemPostMapper;

    //构造方法
    public SystemPostServiceImpl(SystemPostMapper systemPostMapper) {
        super(systemPostMapper);
        this.systemPostMapper = systemPostMapper;
    }

    /**
     * 查询岗位
     *
     * @param querySystemPostByTypeReq
     * @return
     */
    @Override
    public ResultData querySystemPostByType(QuerySystemPostByTypeReq querySystemPostByTypeReq) {

        List<SystemPostPO> pos = systemPostMapper.queryByTypeIdAndIsTeach(querySystemPostByTypeReq.getPostTypeId(), querySystemPostByTypeReq.getIsTeachSeries());
        List<QuerySystemPostByTypeRsp> rsps = Optional.ofNullable(pos).orElse(new ArrayList<>())
                .stream().map(po -> {
                    QuerySystemPostByTypeRsp rsp = new QuerySystemPostByTypeRsp();
                    rsp.setId(po.getId());
                    rsp.setPostName(po.getPostName());
                    rsp.setPostRankName(po.getPostRankName());
                    return rsp;
                }).collect(Collectors.toList());
        return ResultData.success(rsps);
    }
}